package pers.qianyu.month_202011.date_20201111;

/**
 * 53. 最大子序和
 * https://leetcode-cn.com/problems/maximum-subarray/
 * @author mizzle rain
 * @date 2020-11-11 20:32
 */
public class MaxSubArray {
    public int maxSubArray(int[] nums) {
        if (nums == null || nums.length == 0) {
            return -1;
        }
        int res = nums[0];
        int a = 0;
        int b = res;
        for (int i = 1; i < nums.length; i++) {
            a = Math.max(nums[i], nums[i] + b);
            b = a;
            res = Math.max(res, a);
        }
        return res;
    }
}
